package com.gbq.qimo.servlet;

import com.gbq.qimo.pojo.Student;
import com.gbq.qimo.service.StudentService;
import com.gbq.qimo.service.impl.StudentServiceImpl;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

/**
 * @ClassName UpdateStudentById
 * @Description TODO
 * @Author guobenqi
 * @Date 2021/5/29 22:23
 */
@WebServlet("/updateStudent")
public class UpdateStudentById extends HttpServlet {
    private StudentService studentService = new StudentServiceImpl();
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");

         Map<String, String[]> map = request.getParameterMap();
        Student student = new Student();
        try{
            BeanUtils.populate(student,map);
        }catch (InvocationTargetException e){
            e.printStackTrace();
        }catch (IllegalAccessException e){
            e.printStackTrace();
        }
        Integer count = studentService.updateStudent(student);
        response.sendRedirect(request.getContextPath()+"/findStudentByPage");
    }
}
